#include "IGraph.hpp"
#include "GraphFactory.hpp"
#include "Nibbler.hpp"
#include "exceptions.hpp"
#include <iostream>
#include <cstdlib>

int	main(int argc, char **argv)
{
  IGraph *g;
  int x;
  int y;

  if (argc != 4)
    {
      std::cerr << "./nibbler width height lib.so" << std::endl;
      return (-1);
    }

  x = atoi(argv[1]);
  y = atoi(argv[2]);

  try
    {
      if ((x % 16) || (y % 16) || (x < 512) || (y < 480) || (x > 1920) || (y > 1080))
        throw BadWindowProportions(x, y);

      g = GraphFactory::getGraphics(argv[3], argc, argv, x, y);

      Nibbler nibbler(g, x, y);
      nibbler.run();

      GraphFactory::deleteGraphcis(g);
    }
  catch (std::exception &e)
    {
      std::cerr << e.what() << std::endl;
    }

  return 0;
}
